import { BasicMarker } from '../../js/BasicMarker.js';
import { BasicMarkers } from '../../js/BasicMarkers.js';
import { getMarkerIcon } from '../../js/icon.js';
import { getMapEventPoint } from '@gis/lib/api';
import { useUserInfoStore } from '@gis/lib/pinia/userInfo.js';
import { handleCommonRes } from '@gis/lib/utils/resolver.js';

import { netAndScenicDataStore } from '@gis/lib/pinia/netAndScenic.js';
import { openEventDetailsDialog } from '../../../../views/event-manage/event-opt.js';

class Marker extends BasicMarker {
  constructor({ map, data }) {
    super({ map, data });
    this.type = 'cysj';
    super.create();
  }
  getIcon() {
    return getMarkerIcon(this.type);
  }
  getIconOption(icon) {
    return {
      content: `<div style="width: 52px;height: 96px;background: url(${icon}) center center no-repeat;background-size: 100% 100%"></div>`,
      offset: new AMap.Pixel(0, 0),
    };
  }
  onClick() {
    openEventDetailsDialog(this.data.id);
  }
}

export default class Cysj extends BasicMarkers {
  constructor({ map }) {
    super();
    this.map = map;
  }
  createMarker(data) {
    return new Marker({ map: this.map, data });
  }
  async getDataAsync() {
    const { area_code } = useUserInfoStore();
    const { scenicIds } = netAndScenicDataStore();
    const data = await handleCommonRes(getMapEventPoint, {
      area_code: scenicIds && scenicIds.split(',').length == 1 ? scenicIds : area_code,
    });
    return data.map((item) => Object.assign(item, { lnglat: [item.longitude, item.latitude] }));
  }
}
